﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LPV_POS.Module;
using CrystalDecisions.Shared;
using System.Data;
using LPV_POS.Baocao;
using LPV_POS.Baocao.Ellic;


    class Mod_baocaodoanhthu_tatca
    {

        public string str_loaibaocao = "";
        Mod_baocao baocao;
        public void rpt_baocaodoanhthu_tatca( DataSet ds, string path_excel, string tongcongchuatanggiam, string giamgia_1,
                                               string lbel_vat_1, string thuedichvu_1, string tientip_1, string tongcongdagiamthue, string datanggiam, decimal dc_tienmat, decimal dc_the) // bc httt, editor: PL, date: 2012.07.25
        {

            bc_tatcadoanhthu CrReport = new bc_tatcadoanhthu();
            try
            {

                Mod_header_report header_report = new Mod_header_report();
                header_report.f_header_report(CrReport);
                baocao = new Mod_baocao();
                CrystalDecisions.CrystalReports.Engine.TextObject str_thoigian;
                str_thoigian = (CrystalDecisions.CrystalReports.Engine.TextObject)CrReport.ReportDefinition.ReportObjects["txt_tungaydenngay"];
                if (Variable.str_tungay != "")
                {
                    str_thoigian.Text = Variable.str_tungay;
                }
                else
                {
                    str_thoigian.Text = "";
                }
               // bc_tatcadoanhthu rpt = new bc_tatcadoanhthu();

                if (ds.Tables[0].Rows.Count > 0)
                {
                            // Doanh thu tong quat
                            CrystalDecisions.CrystalReports.Engine.TextObject tongcong_1;
                            tongcong_1 = (CrystalDecisions.CrystalReports.Engine.TextObject)CrReport.ReportDefinition.ReportObjects["txt_tongcong_1"];

                            float iTHANHTIENTRUOC = 0;
                            float.TryParse(ds.Tables[0].Rows[0]["THANHTIENTRUOC"] + "", out iTHANHTIENTRUOC);
                            tongcong_1.Text = iTHANHTIENTRUOC.ToString("N0");

                            CrystalDecisions.CrystalReports.Engine.TextObject giamgia;
                            giamgia = (CrystalDecisions.CrystalReports.Engine.TextObject)CrReport.ReportDefinition.ReportObjects["txt_giamgiam"];
                            int gg = 0;
                            int.TryParse(ds.Tables[0].Rows[0]["CHIECKHAU"].ToString(), out gg);
                            giamgia.Text = gg.ToString("N0");

                            CrystalDecisions.CrystalReports.Engine.TextObject thevat;
                            thevat = (CrystalDecisions.CrystalReports.Engine.TextObject)CrReport.ReportDefinition.ReportObjects["txt_thuevat"];
                            int tv = 0;
                            int.TryParse(ds.Tables[0].Rows[0]["VAT"].ToString(), out tv);
                            thevat.Text = tv.ToString("N0");

                            CrystalDecisions.CrystalReports.Engine.TextObject thuedichvu;
                            thuedichvu = (CrystalDecisions.CrystalReports.Engine.TextObject)CrReport.ReportDefinition.ReportObjects["txt_thuedichvu"];
                            int tdv = 0;
                            int.TryParse(ds.Tables[0].Rows[0]["SERVICE_CHARGE"].ToString(), out tdv);
                            thuedichvu.Text = tdv.ToString("N0");

                            CrystalDecisions.CrystalReports.Engine.TextObject tientip;
                            tientip = (CrystalDecisions.CrystalReports.Engine.TextObject)CrReport.ReportDefinition.ReportObjects["txt_tientip"];
                            int tt = 0;
                            int.TryParse(ds.Tables[0].Rows[0]["TIENTIP"].ToString(), out tt);
                            tientip.Text = tt.ToString("N0");

                            CrystalDecisions.CrystalReports.Engine.TextObject tongcong_2;
                            tongcong_2 = (CrystalDecisions.CrystalReports.Engine.TextObject)CrReport.ReportDefinition.ReportObjects["txt_tongcong_2"];
                            float ck = 0;
                            float.TryParse(ds.Tables[0].Rows[0]["CHIECKHAU"].ToString(), out ck);
                            tongcong_2.Text = (iTHANHTIENTRUOC - ck).ToString("N0");

                            CrystalDecisions.CrystalReports.Engine.TextObject tongcong_3;
                            tongcong_3 = (CrystalDecisions.CrystalReports.Engine.TextObject)CrReport.ReportDefinition.ReportObjects["txt_tongcong_3"];
                            float iTHANHTIEN = 0;
                            float.TryParse(ds.Tables[0].Rows[0]["THANHTIEN"] + "", out iTHANHTIEN);
                            tongcong_3.Text = iTHANHTIEN.ToString("N0");

                            CrystalDecisions.CrystalReports.Engine.TextObject tientrongket;
                            tientrongket = (CrystalDecisions.CrystalReports.Engine.TextObject)CrReport.ReportDefinition.ReportObjects["txt_tientrongket"];
                            tientrongket.Text = iTHANHTIEN.ToString("N0");

                            // bc httt, editor: PL, date: 2012.07.25
                            CrystalDecisions.CrystalReports.Engine.TextObject txt_tienmat;
                            txt_tienmat = (CrystalDecisions.CrystalReports.Engine.TextObject)CrReport.ReportDefinition.ReportObjects["txt_tienmat"];
                            txt_tienmat.Text = dc_tienmat.ToString("N0");

                            CrystalDecisions.CrystalReports.Engine.TextObject txt_the;
                            txt_the = (CrystalDecisions.CrystalReports.Engine.TextObject)CrReport.ReportDefinition.ReportObjects["txt_the"];
                            txt_the.Text = dc_the.ToString("N0");
                            //end 2012.07.25
                }
                
                // DOI VOI NHOM CHU
                CrReport.Subreports[1].SetDataSource(ds.Tables[1]);
                CrReport.Subreports[1].DataDefinition.FormulaFields["NHOMCHU"].Text = "{dt_report.NHOMCHU}" + "";
                CrReport.Subreports[1].DataDefinition.FormulaFields["THANHTIEN"].Text = "{dt_report.THANHTIENTRUOC}" + "";
                CrReport.Subreports[1].DataDefinition.FormulaFields["CHENHLECH"].Text = "{dt_report.CHENHLECH}" + "";
                CrReport.Subreports[1].DataDefinition.FormulaFields["TIENMAT"].Text = "{dt_report.TIENMAT}" + "";
                CrReport.Subreports[1].DataDefinition.FormulaFields["TYLE"].Text = "{dt_report.TYLE}" + "";
                // DOI VOI NHOM HANG
                CrReport.Subreports[0].SetDataSource(ds.Tables[3]);
                CrReport.Subreports[0].DataDefinition.FormulaFields["NHOMHANG"].Text = "{dt_report.NHOMHANG}" + "";
                CrReport.Subreports[0].DataDefinition.FormulaFields["THANHTIEN"].Text = "{dt_report.THANHTIENTRUOC}" + "";
                CrReport.Subreports[0].DataDefinition.FormulaFields["CHENHLECH"].Text = "{dt_report.CHENHLECH}" + "";
                CrReport.Subreports[0].DataDefinition.FormulaFields["TIENMAT"].Text = "{dt_report.TIENMAT}" + "";
                CrReport.Subreports[0].DataDefinition.FormulaFields["TYLE"].Text = "{dt_report.TYLE}" + "";
              
                // DOI VOI KHU VUC
                CrReport.Subreports[2].SetDataSource(ds.Tables[7]);
                CrReport.Subreports[2].DataDefinition.FormulaFields["KHUVUC"].Text = "{dt_report.TENBAN}" + "";
                //     CrReport.Subreports[4].DataDefinition.FormulaFields["TENBAN"].Text = "{dt_report.BAN}" + "";
                CrReport.Subreports[2].DataDefinition.FormulaFields["THANHTIEN"].Text = "{dt_report.THANHTIENTRUOC}" + "";
                CrReport.Subreports[2].DataDefinition.FormulaFields["CHENHLECH"].Text = "{dt_report.CHENHLECH}" + "";
                CrReport.Subreports[2].DataDefinition.FormulaFields["TIENMAT"].Text = "{dt_report.TIENMAT}" + "";
                CrReport.Subreports[2].DataDefinition.FormulaFields["TYLE"].Text = "{dt_report.TYLE}" + "";

             
                // DOI VOI HANG HOA
                CrReport.Subreports[3].SetDataSource(ds.Tables[5]);
                CrReport.Subreports[3].DataDefinition.FormulaFields["MAHH"].Text = "{dt_report.MAHH}" + "";
                CrReport.Subreports[3].DataDefinition.FormulaFields["TENHH"].Text = "{dt_report.HANGHOA}" + "";
                CrReport.Subreports[3].DataDefinition.FormulaFields["THANHTIEN"].Text = "{dt_report.THANHTIENTRUOC}" + "";
                CrReport.Subreports[3].DataDefinition.FormulaFields["CHENHLECH"].Text = "{dt_report.CHENHLECH}" + "";
                CrReport.Subreports[3].DataDefinition.FormulaFields["TIENMAT"].Text = "{dt_report.TIENMAT}" + "";
                CrReport.Subreports[3].DataDefinition.FormulaFields["SOLUONG"].Text = "{dt_report.SOLUONG}" + "";
                CrReport.Subreports[3].DataDefinition.FormulaFields["TYLE"].Text = "{dt_report.TYLE}" + "";

                // DOI VOI BAN
                CrReport.Subreports[4].SetDataSource(ds.Tables["Table9"]);
                CrReport.Subreports[4].DataDefinition.FormulaFields["KHUVUC"].Text = "{dt_report.KHUVUC}" + "";
                CrReport.Subreports[4].DataDefinition.FormulaFields["BAN"].Text = "{dt_report.HANGHOA}" + "";
                CrReport.Subreports[4].DataDefinition.FormulaFields["THANHTIEN"].Text = "{dt_report.THANHTIENTRUOC}" + "";
                CrReport.Subreports[4].DataDefinition.FormulaFields["CHENHLECH"].Text = "{dt_report.CHENHLECH}" + "";
                CrReport.Subreports[4].DataDefinition.FormulaFields["TIENMAT"].Text = "{dt_report.TIENMAT}" + "";
                CrReport.Subreports[4].DataDefinition.FormulaFields["TYLE"].Text = "{dt_report.TYLE}" + "";


                //   xuat file excel
                ExportOptions CrExportOptions;

                DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
                ExcelFormatOptions CrFormatTypeOptions = new ExcelFormatOptions();
                CrDiskFileDestinationOptions.DiskFileName = path_excel;
                CrExportOptions = CrReport.ExportOptions;
                CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                CrExportOptions.ExportFormatType = ExportFormatType.Excel;
                CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
                CrExportOptions.FormatOptions = CrFormatTypeOptions;
                CrReport.Export();

            }
            catch (Exception ex)
            {

                CrReport.Dispose();

                System.Windows.Forms.MessageBox.Show(ex.Message, "Thông báo");
                //throw;
            }
            CrReport.Dispose();
        }



    }

